<?php
if (is_home())
{
?>
			<div class="content_box_sidebar">
				<div class="box_title">
					<div class="left">UPCOMING EVENTS</div>
					<!--
					<div class="right"><a href="<?php echo tribe_get_gridview_link(); ?>">view all</a></div>
					-->
					<div class="right"><a href="<?php echo wts_get_link('event_previews'); ?>">view all</a></div>
				</div>
				<div class="listing">
				<?php
//				$lu_posts = tribe_get_events( 'eventDisplay=upcoming&numResults=5'); //--Removed by Surojit as a fix for events starting from the current date
                                //Refer: http://wordpress.org/support/topic/plugin-the-events-calendar-upcoming-vs-current-events
                                $lu_posts = tribe_get_events(array('eventDisplay'=>'upcoming','posts_per_page'=>-1));
				remove_filter('the_content', 'wpautop');
				add_filter('the_title', 'strtoupper');
                                $time_now = time();
                                $count =0;
				foreach( $lu_posts as $post )
				{
                                        $date_post = strtotime($post->EventStartDate);
                                        if($date_post < $time_now ) { continue; }
                                        setup_postdata($post);
                                	?>
						<div class="list_item">
                                                    <span><?php echo tribe_get_start_date(); ?> to <?php echo tribe_get_end_date();?></span><br />
						<a href="<?php tribe_event_link(); ?>"><h2><?php echo strtoupper(the_title()); ?></h2></a>
						<span>Venue: <?php echo tribe_get_venue() . '  ' . tribe_get_city(); ?></span>
						</div>
					<?php
                                        $count++;
                                        if($count >=5) { break;}
				}
				remove_filter('the_title', 'strtoupper');
				?>
				</div>
				<br />
				<div class="box_title">
					<div class="left">FEATURED VIDEO</div>
					<div class="right"><a href="">view all</a></div>
				</div>
				<div class="listing">
				<iframe class="youtube-player" type="text/html" height="250" src="http://www.youtube.com/embed/_Zns7Id1ix0" frameborder="0">
				</iframe>
				</div>
				<br />
				<!-- Advertisement -->
				<img src="images/ad_big.jpg" alt="John Mayer Fender" title="" width="300" height="399" />
			</div>
	<?php
                        } elseif (is_single()) {
	?>

			<div class="content_box_sidebar">
				<?php	
	// checking if the current single page is an event related page. If it is, get the correct $event_id
	// and use that to get the other tab buttons.
	$event_id = -1;
	if ('tribe_events' == get_query_var('post_type')) {
		$event_id = $post->ID;
		$at = 'preview';
	} else {
		$cats = get_the_category();
		foreach ($cats as $cat) {
			if ($cat->slug == 'events') {
				$event_id = get_post_meta($post->ID, '_parent_id', TRUE);
				$at = 'review';
				break;
			}
			if ($cat->slug == 'events-gallery') {
				$event_id = get_post_meta($post->ID, '_parent_id', TRUE);
				$at = 'gallery';
				break;
			}
		}
	}
	if ($event_id != -1 && !empty($event_id)) {

		$status = array('gallery' => 'off',
						'review' => 'off',
						'preview' => 'off'
						);		
		if (array_key_exists($at, $status)) {
			$status[$at] = 'on';
		}
	?>
		<div class="tribe-events-calendar-buttons"">
		<?php		
			// Both the queries objects need to be created before the_post is called so the the $post global
			// variable still points the Main Query.
			echo '<a class="tribe-events-button-' . $status['preview'] . '" href="' . get_permalink($event_id) . '">Preview</a><br />';
			
			$review_query = new WP_Query(array('meta_key' => '_parent_id', 'meta_value' => $event_id, 'category_name' => 'events'));
			if ( $review_query->have_posts() ) {
				$review_query->the_post();
				echo '<a class="tribe-events-button-' . $status['review'] . '" href="' . get_permalink() . '">Review</a><br />';
			}
			
			$gallery_query = new WP_Query(array('meta_key' => '_parent_id', 'meta_value' => $event_id, 'category_name' => 'events-gallery'));
			if ( $gallery_query->have_posts() ) {
				$gallery_query->the_post();
				echo '<a class="tribe-events-button-' . $status['gallery'] . '" href="' . get_permalink() . '">Gallery</a><br />';
			}
			wp_reset_postdata();
			?>
		</div>
	<?php
	}

	// Getting the related articles for the current article.
    $orig_post = $post;
    $tags = wp_get_post_tags($post->ID);
	?>
				<div class="box_title">
					<div class="left">RELATED ARTICLES</div>
				</div>
				<?php
    if ($tags) {
	    $tag_ids = array();
	    foreach($tags as $individual_tag) {
	    	$tag_ids[] = $individual_tag->term_id;
	    }
	    $args=array(
	    'tag__in' => $tag_ids,
	    'post__not_in' => array($post->ID),
	    'posts_per_page'=>5, // Number of related posts that will be shown.
	    'caller_get_posts'=>1
	    );
	    $relposts_query = new wp_query( $args );
	    if( $relposts_query->have_posts() ) {
		    while( $relposts_query->have_posts() ) {
			    $relposts_query->the_post(); ?>
				<div class="topline">
					<div class="list_item">
					<b><?php echo get_the_date('D, jS F'); ?></b><br />
					<a href="<?php the_permalink(); ?>"><h2><?php echo the_title(); ?></h2></a>
					</div>
				</div>
		    <?php }
	    } else {
	    	?><br />
	    	No related posts.<br />
	    	<?php
	    }
    }
    $post = $orig_post;
    wp_reset_query();
	?>
<div class="fb-like" data-href="<?php the_permalink(); ?>" data-send="false" data-layout="box_count" data-show-faces="true" data-font="lucida grande"></div>

<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-text="<?php the_title(); ?>" data-count="vertical">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

<g:plusone size="tall"></g:plusone>		
			
			</div>
			
			<?php
}
dynamic_sidebar( 'primary-widget-area' );
// A second sidebar for widgets, just because.
if ( is_active_sidebar( 'secondary-widget-area' ) ) :
	dynamic_sidebar( 'secondary-widget-area' );
endif;